﻿using System;
using System.Net.Http;
using System.Threading;
using Newtonsoft.Json;
using RestTemplateCore;

namespace RestTemplateCoreDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var httpClient = new HttpClient())
            {
                while (true)
                {
                    var restTemplateClient = new RestTemplate(httpClient)
                    {
                        ConsulServerUrl = "http://127.0.0.1:8500"
                    };

                    var requestContext = new
                    {
                        PhoneNum = "13153181639",
                        Msg = "SOSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
                    };

                    var response = restTemplateClient.PostAsync($"http://MsgService/api/SMS/Send_HW", requestContext).Result;

                    Console.WriteLine($"ResponseCode:{response.StatusCode}");

                    Thread.Sleep(500);
                }
                //===================

                /*

                var response = restTemplateClient.GetForEntityAsync<Product[]>($"http://ProductService/api/Product").Result;

                Console.WriteLine($"ResponseStatus:{response.StatusCode}");

                foreach (var item in response.Body)
                {
                    Console.WriteLine(JsonConvert.SerializeObject(item));
                }
                */

                //===================

                /*
                var response = restTemplateClient.GetForEntityAsync<Product>($"http://ProductService/API/Product/2").Result;

                Console.WriteLine($"ResponseStatus:{response.StatusCode}");

                Console.WriteLine(JsonConvert.SerializeObject(response.Body));
                */

            }

            Console.ReadKey();
        }
    }
    public class Product
    {
        public long Id { get; set; }

        public string Name { get; set; }

        public decimal Price { get; set; }

        public string Description { get; set; }
    }
}
